//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow
{
    using System;
    using System.Collections.ObjectModel;
    using System.Windows;
    using Microsoft.Research.ScientificWorkflow.TridentModel;

    /// <summary>
    /// Interaction logic for DataTypesLegendCtrl.xaml
    /// </summary>
    public partial class DataTypesLegendCtrl : Window
    {
        /// <summary>
        /// Legend Close event.
        /// </summary>
        public event EventHandler OnLegendClose;

        /// <summary>
        /// Occurs on control visibility changed.
        /// </summary>
        public event DependencyPropertyChangedEventHandler OnControlVisibilityChanged;

        /// <summary>
        /// This stores the Datatypes which are shown to user.
        /// </summary>
        private ObservableCollection<DataTypeModel> shownDataTypes = new ObservableCollection<DataTypeModel>();

        /// <summary>
        /// Gets the datatypes which are shown.
        /// </summary>
        public ObservableCollection<DataTypeModel> ShownDataTypes
        {
            get
            {
                return this.shownDataTypes;
            }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        public DataTypesLegendCtrl()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(this.OnClosing);
            this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(this.DataTypesLegendCtrlIsVisibleChanged);
            this.listDatatypes.DataContext = this;
        }

        /// <summary>
        /// Handles the change in visibility of the data type window.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private void DataTypesLegendCtrlIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.OnControlVisibilityChanged != null)
            {
                this.OnControlVisibilityChanged.Invoke(sender, e);
            }
        }

        /// <summary>
        /// Evenhandler for close.
        /// </summary>
        /// <param name="sender">DataTypesLegendCtrl.</param>
        /// <param name="e">CancelEventArgs</param>
        private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;

            if (this.OnLegendClose != null)
            {
                this.OnLegendClose.Invoke(sender, new EventArgs());
            }

            this.Hide();
        }

        /// <summary>
        /// Handles the Click event of the Button control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Called when [mouse left button down].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void OnMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}
